
package com.webster.isw.core.scheduler.listener;

import com.webster.isw.core.service.TriggerService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * ClassName: JobListener
 * Description: 作业监听器
 * Author: wangkang
 * Date: 2014年2月8日
 */
public class JobDetailListener implements org.quartz.JobListener {

    /**
     * Field log: 日志
     */
    private Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * Field triggerService: 触发器监听服务
     */
    @Resource
    private TriggerService triggerService;

    @Override
    public String getName() {
        return "jobListener";
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext context) { // 4
        try {
            this.triggerService.saveIntentStartJob(context);
        } catch (Exception e) {
            this.log.error("jobToBeExecuted:", e);
        }
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext context) { // 5
        try {
            this.triggerService.saveVetoedJob(context);
        } catch (Exception e) {
            this.log.error("jobExecutionVetoed:", e);
        }
    }

    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { // 6
        try {
            this.triggerService.saveCompletedJob(context, jobException);
        } catch (SchedulerException e) {
            this.log.error("jobWasExecuted:", e);
        }
    }

}
